home *** CD-ROM | disk | FTP | other *** search
/ Best Tools for JAVA / Best Tools for JAVA.iso / JAVA_ALL / JAVA_UTL / C2JAVA / C2J.SH < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  1996-04-17  |  3.9 KB  |  145 lines

  1. #!/bin/sh
  2. ############################################################################## 
  3. #  c2j            96/04/04   Chris Laffra
  4. #  Copyright (c) 1995-1996 Morgan Stanley & Co., Inc. All Rights Reserved.
  5. #  Permission to use, copy, modify, and distribute this software
  6. #  and its documentation for NON-COMMERCIAL purposes and without
  7. #  fee is hereby granted provided that this copyright notice
  8. #  appears in all copies. Please contact email: laffra@ms.com
  9. #  for further copyright and licensing information.
  10. #  MORGAN STANLEY MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY 
  11. #  OF THIS SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  12. #  TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  13. #  PARTICULAR PURPOSE, OR NON-INFRINGEMENT. MORGAN STANLEY SHALL NOT BE LIABLE 
  14. #  FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  15. #  DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  16. #  Please refer to the README file.
  17. # This shell script requires: 
  18. #    dirname, sed, and cc (we're only using the C pre-processor)
  19. # Alex Epshteyn <infolink@panix.com>, gave advise for the Win32/MKS version.
  20. ############################################################################## 
  21.  
  22. BASEDIR=`dirname $0`
  23.  
  24. usage() {
  25. cat <<'EOF'
  26.  
  27.   usage: c2j classname
  28.  
  29.   make sure that file <classname>.[H/h/hpp] and <classname>.[C/c/cpp] exist 
  30.   in this directory.  The header file should contain the class declaration 
  31.   of the classes you want to translate. Furthermore, all method bodies 
  32.   should be listed in either the header and/or the other file.
  33.  
  34. EOF
  35. }
  36.  
  37. if test $# -eq 0
  38. then
  39.     usage
  40. fi
  41. if [ ! -d __c2j_java__ ]
  42. then
  43.     mkdir __c2j_java__
  44. fi
  45.  
  46. for i do
  47.     rm -f __c2j_java__/*
  48.     h=$i.H
  49.     if test -f $h; then :
  50.     else
  51.     h=$i.h
  52.     fi
  53.     if test -f $h; then :
  54.     else
  55.     h=$i.hpp
  56.     fi
  57.     if test -f $h
  58.     then 
  59.       echo ""
  60.       echo "c2j, Version 1.0a, 96/01/25"
  61.       echo "Copyright (c) 1995-1996 Morgan Stanley & Co., Inc."
  62.       echo "All Rights Reserved. "
  63.  
  64.       echo ""
  65.       echo "This software comes with a disclaimer."
  66.       echo -n "Did you read the disclaimer and can you accept it? (y/n) "
  67.       read x
  68.       case $x in y*) ;; *)  exit 1; esac
  69.  
  70.       c=$i.C
  71.       if test -f $c; then :
  72.       else
  73.       c=$i.c
  74.       fi
  75.       if test -f $c; then :
  76.       else
  77.       c=$i.cpp
  78.       fi
  79.  
  80.       echo ""
  81.       echo "parsing files \"$h\" and \"$c\""
  82.       echo ""
  83.  
  84.       if [ ! -f $BASEDIR/parser ]
  85.       then
  86.       echo 
  87.       echo "ERROR!!!!"
  88.       echo 
  89.       echo parser not found.
  90.       echo First compile parser.C with any C++ compiler you can find.
  91.       echo Exiting.
  92.       echo 
  93.       exit 0
  94.       fi
  95.  
  96.       #
  97.       # the first pass will run a dangerous sed script, as it translate
  98.       # all occurrences of "unsigned" into "int" for instance, independent
  99.       # of the location. This is a quick hack, should integrate into parser.
  100.       #
  101.       # pass one will insert #include statements for each method declared
  102.       # in the java class. Each inlined C++ method found in the .H file
  103.       # is saved in the __c2j_java__ directory.
  104.       #
  105.       sed -f $BASEDIR/sedin0 $h | $BASEDIR/parser  > __c2j_java__/$i.j
  106.  
  107.       #
  108.       # pass two will detect each C++ method in the .C file, and save it
  109.       # in the __c2j_java__ directory.
  110.       #
  111.       sed -f $BASEDIR/sedin0 $h | $BASEDIR/parser -C > /dev/null
  112.       sed -f $BASEDIR/sedin0 $c | $BASEDIR/parser -C > /dev/null
  113.  
  114.       #
  115.       # the C preprocessor (-E) will resolve all the #include's and
  116.       # finally weave everything together.
  117.       # May generate errors like "cannot find include file ...."
  118.       #
  119.       # sedin1 contains some extra rules for indenting the body of the
  120.       # member functions, for instance.
  121.       # 
  122.       cc -E __c2j_java__/$i.j 2>__c2j_java__/cc.out | \
  123.                 sed -f $BASEDIR/sedin1 > $i.java 
  124.  
  125.       sed -f $BASEDIR/sedin2 __c2j_java__/cc.out
  126.  
  127.       echo
  128.       echo "c2j: Informational: created file" $i.java
  129.       echo
  130.     else
  131.       usage
  132.       exit
  133.     fi
  134. done
  135.  
  136.